using UnityEngine;
using DG.Tweening;
using DG.Tweening.Core;

namespace Miao.UI
{
    public class PopUpUIMotion : BaseUIMotion
    {
        Tweener tweenerhandle;
        private float _duration;
        private Vector3 baselocalScale;


        public PopUpUIMotion(float duration = 1f)
        {
            _duration = duration;

        }
        public override void Init()
        {
            baselocalScale = TweenGameObject.transform.localScale;
        }

        public override void Play(bool forward, TweenCallback complete)
        {
            if(tweenerhandle != null)
            {
                tweenerhandle.Complete();
                tweenerhandle = null;
            }

            Vector3 fromScale = forward ? Vector3.zero : baselocalScale;
            Vector3 toScale = forward ? baselocalScale : Vector3.zero;

            TweenGameObject.transform.localScale = fromScale;
            tweenerhandle = TweenGameObject.transform.DOScale(toScale, _duration);
            tweenerhandle.SetEase(forward ? Ease.OutElastic : Ease.InElastic);
            tweenerhandle.OnComplete(complete);
        }
    }
}